
using System.Threading;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections.Generic;
namespace com.tc.gateway.tunnel
{

    public class MultiInputStream : MemoryStream
    {

        IPEndPoint group = null;
        UdpClient socket = null;
        MemoryStream ms = new MemoryStream();
        int port;
        public MultiInputStream(IPEndPoint g, UdpClient s, int po)
        {

            this.group = g;
            this.socket = s;
            this.port = po;

            Thread ts = new Thread(run);
            ts.Start();
        }

        public void run()
        {

            IPEndPoint remoteHost = null;

            while (true)
            {

                byte[] buf = socket.Receive(ref remoteHost);

                string s = Encoding.Default.GetString(buf, 0, buf.Length);
                if (s.Length <= 3)
                {
                    //System.err.println(s);
                    continue;
                }
                ms.Write(buf, 0, buf.Length);
                ms.Flush();


                Thread.Sleep(1000);

            }


        }
        override
        public int ReadByte()
        {


            return ms.ReadByte();

        }


        override
        public int Read(byte[] bytes, int offset, int count)
        {
            return ms.Read(bytes, offset, count);

        }


    }
}